.set				noreorder

.equ				INJECTOR_OFFSET, 0x00402000

;ROM
;.org				0xB1F4392C
;RAM
;.org				no_idea_could_be_anywhere_lol

LUI	S0,	0xB1FF		;
ORI	S0,	S0,	0xDC00	;Kilobyte before the trainer
LUI	S1,	%hi(0x80000000 + INJECTOR_OFFSET)		;
ORI	S1,	S1,	%lo(0x80000000 + INJECTOR_OFFSET)	;
				;Where the loader stub loader goes
ORI	S2,	R0,	0x0400	;Just using a kilobyte, whatever
BEQZ	R0,			Inject_Loop
NOP

;	Uh some number of nops go here
NOP
NOP
NOP
NOP
NOP
NOP
NOP
;	Apparently 7
				Unaltered_JAL:
JAL				0x000000C4
NOP				;The JAL is modified by other code before this is executed

				Inject_Loop:
LW	S3,	0x0000	(S0)	;
LW	RA,	0x0000	(S1)	;
BNEL	S3,	RA,		Inject_Write
SW	S3,	0x0000	(S1)	;
				Inject_Write:
ADDIU	S0,	S0,	0x0004	;
ADDIU	S1,	S1,	0x0004	;
BNEZL	S2,			Inject_Loop
ADDIU	S2,	S2,	-0x0004	;

JAL				INJECTOR_OFFSET
NOP
